package com.lin.manager.controller.system;

import com.lin.manager.aop.Log;
import com.lin.manager.common.enums.LogEnum;
import com.lin.manager.common.req.QueryPage;
import com.lin.manager.common.resp.R;
import com.lin.manager.system.entity.SysDeptEntity;
import com.lin.manager.system.service.SysDepartmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @作者: 林江
 * @创建时间: 2024/3/11
 * @功能:
 */
@Api(tags = "部门管理")
@RestController
@RequestMapping("/department")
public class SysDepartmentController {

    @Autowired
    SysDepartmentService departmentService;

    @ApiOperation("部门管理 - 获取所有部门")
    @Log(module = "部门管理", descipt = "获取所有部门", type = LogEnum.SELECT)
    @GetMapping("list")
    public R list(QueryPage page) {
        return R.ok(departmentService.cacheTree(page));
    }

    @ApiOperation("部门管理 - 添加")
    @Log(module = "部门管理", descipt = "添加部门", type = LogEnum.INSERT)
    @PostMapping("add")
    public R add(@RequestBody SysDeptEntity sysDept) {
        departmentService.add(sysDept);
        return R.ok();
    }

    @ApiOperation("部门管理 - 修改部门")
    @Log(module = "部门管理", descipt = "修改部门", type = LogEnum.UPDATE)
    @PostMapping("update")
    public R update(@RequestBody SysDeptEntity sysDept) {
        departmentService.update(sysDept);
        return R.ok();
    }

    @ApiOperation("部门管理 - 删除部门")
    @Log(module = "部门管理", descipt = "删除部门", type = LogEnum.DELETE)
    @DeleteMapping("delete")
    public R del(String id) {
        departmentService.del(id);
        return R.ok();
    }
}
